﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Wicture.QPZS.EPC.API.Domain;
using Wicture.QPZS.EPC.API.Domain.Entities;

namespace Wicture.QPZS.EPC.API.InvokeContextBuilders.InvokeResultAnalysers
{
    public class InvokeResultAnalyserProxy : IInvokeResultAnalyserProxy
    {
        private readonly IInvokeResultAnalyser[] _invokeResultAnalysers;
        private readonly IServiceHandlerSelector _serviceHandlerSelector;

        public InvokeResultAnalyserProxy(IInvokeResultAnalyser[] invokeResultAnalysers, IServiceHandlerSelector serviceHandlerSelector)
        {
            _invokeResultAnalysers = invokeResultAnalysers;
            _serviceHandlerSelector = serviceHandlerSelector;
        }

        public void Analyse(ThrottlingContext context, DbRESTFul.ExecutionContext executionContext)
        {
            var analyse = _serviceHandlerSelector.Select(_invokeResultAnalysers, context);
            analyse?.Analyse(context, executionContext);
        }
    }
}
